<template>
  <div class="fullscreen-container common-container">
    <div class="fullscreen-content">
      <div class="fullscreen-header">
        <div class="title">window切换全屏</div>
        <el-button
          class="fullscreen-btn"
          type="primary"
          @click="fullscreenHandler('window')"
        >
          {{ isWindowFullscreen ? '退出全屏' : '点击全屏'}}
        </el-button>
      </div>
      <div class="fullscreen-dom-content" id="domScreen" @click="fullscreenHandler('dom')" ref="domRef">
        <div class="title">DOM元素切换全屏</div>
        <div class="content-inner">
          <el-button
            class="fullscreen-btn"
            type="primary"
          >
            {{ isDomFullscreen ? '退出全屏' : '点击全屏'}}
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { useFullscreen } from "@vueuse/core";
export default {
  name: 'index',
  data(){
    return{
      isWindowFullscreen: false,
      isDomFullscreen: false,
    }
  },
  mounted () {
    this.init()
  },
  methods:{
    init(){
      const { toggle:fullWindowScreenAction } = useFullscreen();
      window.fullWindowScreenAction = fullWindowScreenAction
      const domScreen = document.getElementById('domScreen')
      const { toggle: fullscreenAction } = useFullscreen(domScreen)
      window.fullscreenAction = fullscreenAction
    },
    fullscreenHandler(type){
      if(type == 'window'){
        this.isWindowFullscreen = !this.isWindowFullscreen
        window.fullWindowScreenAction()
      }else{
        this.isDomFullscreen = !this.isDomFullscreen
        window.fullscreenAction()
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.fullscreen-header{
  height: 100px;
  text-align: left;
  border-bottom: 1px solid #ececec;
}
.title{
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 30px;
}
.fullscreen-btn{
  padding: 8px 10px;
  background: #62afe3;
  border: 1px solid #62afe3;
}
.fullscreen-dom-content{
  width: 300px;
  height: 200px;
  margin: 100px auto;
  padding-top: 100px;
  border: 1px solid #ececec;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  background: white;
}
</style>
